package com.wanghlme.exercise05.web;

import com.wanghlme.exercise05.pojo.Emp;
import com.wanghlme.exercise05.service.IEmpService;
import com.wanghlme.exercise05.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/toMain")
public class ToMainAction extends HttpServlet {
    private IEmpService empService;

    public ToMainAction() {
        empService = new EmpServiceImpl();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Emp> list = empService.listAllEmployee();
        req.setAttribute("empList", list);
        this.getServletContext().getRequestDispatcher("/page/main.jsp").forward(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
